<!DOCTYPE html>
<html lang="en">

<form action="Select2CSV.php" method="post">
开始时间: <input type="date" name="sjj1"><br>
结束时间: <input type="date" name="sjj2"><br>
提示:不输入日期则导出全部<br>
<input type="submit" value=导出>
</form>

  <head>
	
    <meta charset="utf-8">
    <title>三安芯片掃描</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">	
    <link rel="stylesheet" href="./4/lumen/bootstrap.css" media="screen">
    <link rel="stylesheet" href="./_assets/css/custom.min.css">
  </head>
  <body>
  <div class="container">
	<form>
	  <fieldset>
		<legend>三安芯片掃描</legend>
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">工單:</label>
		  <div class="col-sm-10">
		  <input class="form-control" placeholder="W7C14H" id="wo" type="text">
		  </div>
		</div>	
		<div class="row" id="woDesc">	
		</div>
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">掃描二維碼:</label>
		  <div class="col-sm-10">
		  <input class="form-control" placeholder="17620T4003-7250613" id="qr" type="text">
		  
		  </div>
		</div>
		<div class="form-group row">
		  <label class="col-sm-2 col-form-label" for="inputDefault">數量:</label>
		  <div class="col-sm-3">
		  <input readonly=""  class="form-control"  id="qty" type="text">
		  </div>
		  <label class="col-sm-2 col-form-label" for="inputDefault">累加量:</label>
		  <div class="col-sm-3">
		  <input readonly=""  class="form-control"  id="sqty" type="text">
		  </div>
		</div>			
		
		<!-- 这里准备存放当前二维码的信息 -->
		<div class="col-sm-12">
			<div class="card border-dark mb-3" style="max-width: 120rem;">
				<div class="card-header">当前二维码信息：</div>
				<div class="card-body">
					<table class="table table-hover" style="table-layout:fixed" >
					  <thead>
						<tr class="table-active">
						  <th width="10%" scope="col">工单号</th>
						  <th width="10%" scope="col">芯片種類</th>
						  <th width="17%" scope="col">批號</th>
						  <th width="10%" scope="col">規格</th>
						  <th width="7%" scope="col">電壓最小值</th>
						  <th width="7%" scope="col">電壓最大值</th>
						  <th width="7%" scope="col">亮度最小值</th>
						  <th width="7%" scope="col">亮度最大值</th>
						  <th width="7%" scope="col">主波長最小值</th>
						  <th width="7%" scope="col">主波長最大值</th>
						  <th width="7%" scope="col">數量</th>
						  <th width="7%"  scope="col">序号</th>
						  <th width="7%"  scope="col">删除键</th>
						</tr>
					  </thead>
						<tbody id="DQXX">
							<!-- 这里放的是当前扫描的信息的 -->
						</tbody>
					</table>
				</div>
			</div>
		</div>
		<div class="row">	
			<table class="table table-hover" style="table-layout:fixed" >
			  <thead>
				<tr class="table-active">
				  <th width="10%" scope="col">工单号</th>
				  <th width="10%" scope="col">芯片種類</th>
				  <th width="17%" scope="col">批號</th>
				  <th width="10%" scope="col">規格</th>
				  <th width="7%" scope="col">電壓最小值</th>
				  <th width="7%" scope="col">電壓最大值</th>
				  <th width="7%" scope="col">亮度最小值</th>
				  <th width="7%" scope="col">亮度最大值</th>
				  <th width="7%" scope="col">主波長最小值</th>
				  <th width="7%" scope="col">主波長最大值</th>
				  <th width="7%" scope="col">數量</th>
				  <th width="7%"  scope="col">序号</th>
				  <th width="7%"  scope="col">删除键</th>
				</tr>
			  </thead>
			  <tbody id="blues">
			
			  </tbody>
			</table>
		</div>
	  </fieldset>
	</form>
	<p class="lead">
    <a class="btn btn-primary btn-lg" href="index.html" role="button">返回</a>
	</p>
	
	</div>
    <script src="./_vendor/jquery/dist/jquery.min.js"></script>
    <script src="./_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="./_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./_assets/js/custom.js"></script>
	<script>
	var disks;
	var disksB;
	var cks=new Array(20);
		var v1=0,v2=0,h1=0,h2=0,w1=0,w2=0;
		$("#wo").keypress(function(e){ //WO工单号按下回车后的代码
		  console.log($("#wo").val());
		  $("ul").find("li").remove(); //找到li然后干嘛？
		  var key = e.which;
		  if (key == 13) { 
			$.ajax({ url: "getwo.php?lot="+$("#wo").val(), 
					dataType : "text",
					success: function(data){
					wos=data.split(",");//T5C50724L-03,A2996F0,714.240000,晶片/S-35EBMUD-H,2.9-3.2,230-240,455-457.5
					v1=parseFloat(wos[4].split("-")[0]);//v1=工单电压小
					v2=parseFloat(wos[4].split("-")[1]);//v2=工单电压大
					h1=parseFloat(wos[5].split("-")[0]);//h1=工单亮度小
					h2=parseFloat(wos[5].split("-")[1]);//h2=工单亮度大
					w1=parseFloat(wos[6].split("-")[0]);//w1=工单波长小
					w2=parseFloat(wos[6].split("-")[1]);//w2=工单波长大
					
					$("#woDesc").text("");// 清空数据
					html = 
						'<table class="table table-hover">'+
						'  <thead>'+
						'	<tr class="table-active">'+
						'	  <th scope="col">工單號</th>'+
						'	  <th scope="col">成品料號</th>'+
						'	  <th scope="col">芯片料號</th>'+
						'	  <th scope="col">品名規格</th>'+
						'	  <th scope="col">電壓</th>'+
						'	  <th scope="col">亮度</th>'+
						'	  <th scope="col">波長</th>'+
						'	</tr>'+
						'  </thead>'+
						'  <tbody>'+
						'	<tr >'+
						'	  <th scope="row">'+$("#wo").val()+'</th>'+//工單號
						'	  <td>'+wos[0]+'</td>'+//成品料號
						'	  <td>'+wos[1]+'</td>'+//芯片料號
						'	  <td>'+wos[3]+'</td>'+//品名規格
						'	  <td>'+wos[4]+'</th>'+//電壓
						'	  <td>'+wos[5]+'</th>'+//亮度
						'	  <td>'+wos[6]+'</th>'+//波長
						'	</tr>'+
						'  </tbody>'+
						'</table>';	
					$("#woDesc").append(html);	
					$("#qty").val(wos[2]);
				  }
				  });		  
			$("#qr").focus();
		 }
		});	
		//S-30MBMUD-C,17C120650VY008212,457CI155,17045,   --3
		//VF:3.02,3.07,3.10,0.02,  --4，5，6，7
		//PO:155.0,156.7,161.0,1.11, --8，9，10，11
		//WD:457.5,458.2,460.0,0.58,--12，13，14，15
		//00-00-F1-000-000-V
        var sum = 0;
		var i = 0;
		var del_id=null;
		$("#qr").keypress(function(e){//二维码的输入框按下回车
		  console.log($("#qr").val());
		
		  var key = e.which;
		  if (key == 13) {
			qrs=$("#qr").val().split(",");//把二维码的内容拆分
		    i++;
			bg="";//
			vb=parseFloat(qrs[4].split(":")[1]);//vb=扫描电压小
			if (vb<v1) {bg1='bgcolor="red"';} else {bg1='bgcolor="green"';}  
			ve=parseFloat(qrs[6]);//ve=扫描电压大
			if (ve>v2) {bg2='bgcolor="red"';} else {bg2='bgcolor="green"';}  
			hb=parseFloat(qrs[8].split(":")[1]);//hb=扫描亮度小
			if (hb<h1) {bg3='bgcolor="red"';} else {bg3='bgcolor="green"';}
			he=parseFloat(qrs[10]);//he=扫描亮度大
			if (he>h2) {bg4='bgcolor="red"';} else {bg4='bgcolor="green"';}
			wb=parseFloat(qrs[12].split(":")[1]);//wb=扫描波长小
			if (wb<w1) {bg5='bgcolor="red"';} else {bg5='bgcolor="green"';}
			we=parseFloat(qrs[14]);//we=扫描波长大
			if (we>w2) {bg6='bgcolor="red"';} else {bg6='bgcolor="green"';}
			
			//SAVE DB这里开始传输数据到数据库存储
			//日期时间, 工单号, 成品料号, 芯片料号, 芯片规格, 芯片电压, 芯片亮度, 芯片波长, 扫描品号, 扫描批号, 扫描规格, 扫描电压小, 扫描电压大, 扫描亮度小, 扫描亮度大, 扫描波长小, 扫描波长大, 数量, 二维码内容
			//date函数, Str1传入Chip_item参数,传递到php
			//文本=`工单号···················成品料号······芯片料号······规格``·······电压```········亮度```·······波长```·```·工单数量·`````··扫描品号········批号``········规格`········扫描电压小··大······亮度小·····大·······波长小·····大·········数量········二维码内容
			$Str1 = "'"+$("#wo").val()+"', '"+wos[0]+"', '"+wos[1]+"', '"+wos[3]+"', '"+wos[4]+"', '"+wos[5]+"', '"+wos[6]+"', '"+wos[2]+"', '"+qrs[0]+"', '"+qrs[1]+"', '"+qrs[2]+"', '"+vb+"', '"+ve+"', '"+hb+"', '"+he+"', '"+wb+"', '"+we+"', '"+qrs[3]+"', '"+$("#qr").val()+"'"
			$.ajax({ 
					async:false,
					url: "Set2MySQL.php?Chip_item="+$Str1,
					dataType : "text",
					success: function(data){
						del_id = data;
					}
				});
			
			console.log("del_id :"+del_id);
			
			
			html=	'<tr id='+del_id+'>'+
					'<td>'+$("#wo").val()+'</td>'+//工单号,这里是输出网页代码
					'	  <td>'+qrs[0]+'</td> '+//扫描品号
					'	  <td  style="overflow:hidden;white-space:nowrap;text-overflow:ellipsis;">'+qrs[1]+'</td>'+//扫描批号
					'	  <td>'+qrs[2]+'</td>'+//扫描规格
					'	  <td '+bg1+' id="v'+i.toString()+'">'+vb+'</td>'+//扫描电压小
					'	  <td '+bg2+' id="vv'+i.toString()+'">'+ve+'</td>'+//扫描电压大
					'	  <td '+bg3+' id="h'+i.toString()+'">'+hb+'</td>'+//扫描亮度小
					'	  <td '+bg4+' id="hh'+i.toString()+'">'+he+'</td>'+//扫描亮度大
					'	  <td '+bg5+' id="w'+i.toString()+'">'+wb+'</td>'+//扫描波长小
					'	  <td '+bg6+' id="ww'+i.toString()+'">'+we+'</td>'+//扫描波长大
					'	  <td>'+qrs[3]+'</td>'+//扫描数量
					'	  <td>'+del_id+'</td> '+//数据库序号
					'	  <td><button type="button" class="btn btn-primary" onclick="showDetails(this)" id="del'+del_id+'"  data-delid-type="'+del_id+'" >刪除</button>  </td> '+
					'	</tr>';
			sum +=parseFloat(qrs[3]);		
			$("#sqty").val(sum);
			$("#DQXX").text("");// 清空数据
			//这里准备在芯片当前信息框内写入当前二维码信息
			$("#DQXX").append(html)
			$("#blues").append(html);
			$("#qr").select();
		  }
		});	
	function showDetails(del_id){
		var xmlhttp = new XMLHttpRequest();//这里设定JS的原生Ajax才能xmlhttp_open和send
		var delidType = del_id.getAttribute("data-delid-type");//这个是Del_Id
		console.log(delidType)
		console.log("GET,"+"Del4Chip.php?del_id="+delidType)
		
		xmlhttp.open("GET","Del4Chip.php?del_id="+delidType,true);
		
		xmlhttp.send();
		
	}
	</script>
	
  </body>
</html>
